import { message } from 'antd';
import { RcFile } from 'antd/es/upload';

export const beforeUpload = (file: RcFile) => {
  const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
  if (!isJpgOrPng) {
    message.error('只可以上传JPG/PNG文件!');
  }
  const isLt2M = file.size / 1024 / 1024 < 2;
  if (!isLt2M) {
    message.error('图片要小于2MB!');
  }
  return isJpgOrPng && isLt2M;
};
